package zzl.com.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.Job;

import java.io.IOException;

/**
 * Created by EDZ on 2018/3/26.
 */
public class MapReducer {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //Configuration conf = new Configuration();
        //Configuration con = new Configuration();

        System.setProperty("hadoop.home.dir", "E:\\hadoop-2.7.5");
        JobConf conf = new JobConf(MapReducer.class);
        conf.set("mapreduce.app-submission.cross-platform", "true");
        conf.set("dfs.permissions", "false");
        conf.set("fs.defaultFS", "hdfs://zzl-master:9000/");
        conf.set("mapreduce.job.jar", "target/maven-1.0-SNAPSHOT.jar");
        conf.set("mapreduce.framework.name", "yarn");
        conf.set("yarn.resourcemanager.hostname", "zzl-master");
        /**远程运行**/
        conf.set("mapreduce.input.fileinputformat.inputdir", "/input/");
        conf.set("mapreduce.output.fileoutputformat.outputdir", "/wcoutput/");
        /**本地运行**/
        //conf.set("mapreduce.output.fileoutputformat.outputdir","E:/ideawork/maven/bigdata/test/out/");
        //conf.set("mapreduce.input.fileinputformat.inputdir","E:/ideawork/maven/bigdata/test/test.txt");
        conf.setJobName("MapReducer");
        Job job = Job.getInstance(conf);
        job.setMapperClass(WordMapper.class);
        job.setReducerClass(WordReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);
        job.waitForCompletion(true);
    }
}
